package com.feng.show.service.impl;

import com.feng.show.comm.ServerResponse;
import com.feng.show.dao.MerchantMapper;
import com.feng.show.entity.Merchant;
import com.feng.show.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("IMerchantService")
public  class MerchantServiceImpl implements IMerchantService {

    @Autowired
    private MerchantMapper mapper;

    @Override
    public ServerResponse<String> addMerchant(String userId, Merchant merchant) {

        userId="1001";
        if(userId==null){
           return  ServerResponse.createByErrorMsg("请登录");
        }
        if(merchant==null){
            return  ServerResponse.createByErrorMsg("请求错误");
        }
        merchant.setInsertTime(new Date());

        int  statue=mapper.insert(merchant);
        if(statue!=0){
            return  ServerResponse.createBySuccessMsg("保存成功");

        }else{
            return  ServerResponse.createByErrorMsg("保存失败");
        }

    }

    @Override
    public ServerResponse<List<Merchant>> getMerchantList(String userId) {
        userId="1001";
        if(userId==null){
            return  ServerResponse.createByErrorMsg("请登录");

        }

        try{
            List<Merchant> list=mapper.selectByExample(null);
            return ServerResponse.createBySuccesMsg(list);
        }catch(Exception e){
            return  ServerResponse.createByErrorMsg("请求失败");
        }

    }


//    @Override
//    public ServerResponse<String> addProductType(String name, String no, String des) {
//
//
//        long count=serarchByName(name);
//        if(count>0){
//            return  ServerResponse.createBySuccessMsg(name+"已存在，不能重复添加");
//        }
//
//
//        ProductType type=new ProductType();
//        type.setDes(des);
//        type.setName(name);
//        type.setNo(no);
//
//        int status=mapper.insert(type);
//        if(status!=0){
//            return ServerResponse.createBySuccessMsg("增加成功");
//        }else{
//            return ServerResponse.createBySuccessMsg("添加失败");
//        }
//
//    }
//
//    @Override
//    public Long serarchByName(String name) {
//        ProductTypeExample typeExample=new ProductTypeExample();
//        ProductTypeExample.Criteria criteria=typeExample.createCriteria() ;
//        criteria.andNameEqualTo(name);
//
//        long count=mapper.countByExample(typeExample);
//        return count;
//
//    }
//
//    @Override
//    public ServerResponse<List<ProductType>> getProductTypeList(String userId) {
//
//        List<ProductType>  list=mapper.selectByExample(null);
//        return ServerResponse.createBySuccesMsg(list);
//    }
}
